﻿using System;
#if DEBUG
using System.Diagnostics;
#endif // #if DEBUG
using System.Net;
using System.Text;
using System.Xml;
using System.Collections.Generic;

using FRL.DebtChased.Extensions;
using FRL.DebtChased.Repository;

#if WORKFLOWEDITOR
using FRL.DebtChased.WorkflowEditor;
#endif // #if WORKFLOWEDITOR

namespace FRL.DebtChased.WorkflowObjects
{

	/// <summary>
	/// Declaration of WorkflowAction_PhoneCall class
	/// Workflow action for calling debtor, client, agent or solicitor
	/// </summary>
	public class WorkflowAction_PhoneCall : WorkflowAction_Base
	{

		/////////////////////////////////////////////////////////////
		// Constants and enumerations

		public const string XmlElementName = "WorkflowAction_PhoneCall";
		public const string BoingLabel = "CALL";

		/////////////////////////////////////////////////////////////
		// Attributes

		private Definitions.eCommTargetType m_Target = Definitions.eCommTargetType.NotSet;
		public Definitions.eCommTargetType Target
		{
			get { return m_Target; }
			set { m_Target = value; }
		}

		private string m_strReason;
		public string Reason
		{
			get { return m_strReason; }
			set { m_strReason = value; }
		}

		private string m_strMessageForCollector;
		public string MessageForCollector
		{
			get { return m_strMessageForCollector; }
			set { m_strMessageForCollector = value; }
		}

		private string m_strAdditionalNotes;
		public string AdditionalNotes
		{
			get { return m_strAdditionalNotes; }
			set { m_strAdditionalNotes = value; }
		}

		/////////////////////////////////////////////////////////////
		// Implementation

		protected override string _getElementName()
		{
			return XmlElementName;
		}

#if WORKFLOWEDITOR
		public override string GetBoingLabel()
		{
			return BoingLabel;
		}
#endif // #if WORKFLOWEDITOR

#if WORKFLOWEDITOR
		public override string[] GetBoingSubStrings()
		{

			// Declare return variable
			string[] Ftmp = new string[2];

			// row0 - target and reason
			StringBuilder sb = new StringBuilder();
			sb.AppendFormat("To {0}, ", m_Target);
			if (string.IsNullOrEmpty(m_strReason))
				sb.Append("[no reason]");
			else
				sb.Append(m_strReason);
			Ftmp[0] = sb.ToString();

			// Add hint of message in second row
			sb = new StringBuilder();
			if (string.IsNullOrEmpty(m_strMessageForCollector))
			{
				sb.Append("[no message for collector]");
				if(!string.IsNullOrEmpty(m_strAdditionalNotes))
					sb.Append(" (+Notes)");
			}
			else
			{
				if(string.IsNullOrEmpty(m_strAdditionalNotes))
					sb.Append(m_strMessageForCollector);
				else
					sb.AppendFormat("{0} (+Notes)",m_strMessageForCollector);
			}
			Ftmp[1] = sb.ToString();

			// Return variable
			return Ftmp;

		}
#endif // #if WORKFLOWEDITOR

		protected override void _writeParameters(XmlWriter w)
		{

			// Write attributes
			w.WriteAttributeString("target", ((int)m_Target).ToString());
			w.WriteAttributeString("reason",m_strReason);
			w.WriteAttributeString("msgForCollector",m_strMessageForCollector);
			w.WriteAttributeString("addNotes",m_strAdditionalNotes);

		}

		protected override void _readParameters(XmlReader r)
		{

			// Read attributes
			m_Target = (Definitions.eCommTargetType)r.SafeReadIntAttribute("target", (int)Definitions.eCommTargetType.Debtor);
			m_strReason = r.GetAttribute("reason");
			m_strMessageForCollector = r.GetAttribute("msgForCollector");
			m_strAdditionalNotes = r.GetAttribute("addNotes");

		}

		public override string GetSummary(Workflow.eSummaryFormat SummaryFormat)
		{

			// Declare return variable
			string strFtmp = null;

			// Compare formats
			if (SummaryFormat == Workflow.eSummaryFormat.Audit)
			{
				strFtmp = string.Format("Call {0}", m_Target);
			}
			else if (SummaryFormat == Workflow.eSummaryFormat.Clockwork)
			{
				strFtmp = string.Format("Call {0}", m_Target);
			}
#if DEBUG
			else
				Debug.Assert(false);
#endif // #if DEBUG

			// Return variable
			return strFtmp;

		}

#if REPOSITORY
		public override List<AccountNote> Process(DebtChasedEntities ent, Account acc, AccountInvoice inv)
		{

			// Declare return variable
			List<AccountNote> Ftmp = null;

			// Return variable
			return Ftmp;

		}
#endif // #if REPOSITORY

	}

}
